package cn.sixmillions.ps.config;

import com.qingstor.sdk.config.EnvContext;
import com.qingstor.sdk.service.Bucket;
import com.qingstor.sdk.service.QingStor;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 青云OSS存储
 *
 * @author six
 * @since 2023-01-14
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "qing-stor")
public class QingStorConfig {

    private String accessKey;
    private String accessSecret;
    private String bucketName;
    private String zone;
    private String baseUrl;

    @Bean
    public QingStor qingStor() {
        EnvContext env = new EnvContext(accessKey, accessSecret);
        return new QingStor(env);
    }

    @Bean
    public Bucket qingStorBucket(QingStor qingStor) {
        return qingStor.getBucket(bucketName, zone);
    }
}
